package com.jic.order.controller.feign;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jic.common.base.vo.PageResult;
import com.jic.order.api.DistributionOrderApi;
import com.jic.order.entity.OrderGoods;
import com.jic.order.mapper.OrderMapper;
import com.jic.order.request.DistributorOrderRequest;
import com.jic.order.response.OrderGoodsInfo;
import com.jic.order.service.OrderGoodsService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;


@RestController
@RequestMapping("/feign/distributionOrder")
@Api(value = "APi-分销中心", tags = "APi-分销中心")
@Slf4j
public class DistributionOrderFegin implements DistributionOrderApi {

    @Resource
    private OrderGoodsService orderGoodsService;
    @Resource
    private OrderMapper orderMapper;

    @Override
    public OrderGoodsInfo getDistributionOrderInfo(String orderNo) {

        OrderGoods goodsInfoByOrderNo = orderGoodsService.getGoodsInfoByOrderNo(orderNo);
        if (null != goodsInfoByOrderNo) {
            OrderGoodsInfo orderGoodsInfo = new OrderGoodsInfo();
            BeanUtils.copyProperties(goodsInfoByOrderNo, orderGoodsInfo);
            return orderGoodsInfo;
        }
        return null;
    }

    /**
     * 查询分销订单
     *
     * @param distributorOrderRequest
     * @return
     */
    @Override
    public PageResult<OrderGoodsInfo> queryDistributionOrder(DistributorOrderRequest distributorOrderRequest) {
        PageHelper.startPage(distributorOrderRequest.getStart(), distributorOrderRequest.getLimit());
        List<OrderGoodsInfo> orderGoodsInfoList = orderMapper.queryDistributionOrder(distributorOrderRequest);
        PageInfo pageInfo = new PageInfo(orderGoodsInfoList);
        PageResult pageResult = new PageResult();
        pageResult.setRows(orderGoodsInfoList);
        pageResult.setTotal(pageInfo.getTotal());
        return pageResult;
    }
}
